<!-- 首页 -->
<template>
  <view class="bg">
    <view class="person_info" @click="goPersonal">
      <view class="person_info_son">
        <image class="headPortrait" src="@/assets/images/32pt@3x.png" />
        <span>您好,用户{{ userStore.btStaff.btsName }}</span>
      </view>
      <view class="person_info_son site">
        <Location2 />
        <span>福州前横路</span>
      </view>
    </view>
    <OrderNumber class="OrderNumber" :allNum="allNum" :confirmNum="confirmNum" :receiveNum="receiveNum" />
  </view>
  <SearchOrder class="SearchOrder" />
  <view class="footer">
    <view class="item" @click="goWaybill">
      <image class="img" src="@/assets/images/homePage/shouye_icon_wangdianyundan.png" />
      <view>网点运单</view>
    </view>
    <view class="item" @click="goSendRecord">
      <image class="img" src="@/assets/images/homePage/shouye_icon_fahuojilu.png" />
      <view>发货记录</view>
    </view>
    <view class="item" @click="goPickRecord">
      <image class="img" src="@/assets/images/homePage/shouye_icon_tihuochaxun.png" />
      <view>提货查询</view>
    </view>
    <view class="item" @click="goNetQuery">
      <image class="img" src="@/assets/images/homePage/shouye_icon_wangdianchaxun.png" />
      <view>网点查询</view>
    </view>
    <view class="item" @click="goPriceAdd">
      <image class="img" src="@/assets/images/homePage/shouye_icon_jiageshixiao.png" />
      <view>价格时效</view>
    </view>
  </view>
  <myTodoList />
</template>

<script setup lang="ts">
import { Location2 } from '@nutui/icons-vue-taro'
import SearchOrder from '../../components/Home/SearchOrder/index.vue'
import OrderNumber from '../../components/Home/OrderNumber/index.vue'
import myTodoList from '../../components/pendItem/index.vue' // 我的待办组件
import { ref } from 'vue'
import { getByCustomer, waitForConfirm, waitForReceive, waitAscertain } from '../../@api/home'
import useUserStore from '@/store/user'
import dayjs from 'dayjs'
import Taro, { useReady, useDidShow } from '@tarojs/taro'

const userStore = useUserStore()
console.log(userStore, 'SSSSS')

// 如果本地没数据就重新登陆
useDidShow(() => {
  if (!userStore.btStaff.btsName) {
    Taro.showToast({
      icon: 'error',
      title:  '请先登录',

      success() {
        setTimeout(() => {
          Taro.navigateTo({
            url: '/pages3/login/index?redirected=' + window.location.pathname
          })
        }, 1000)
      }
    })
  }
})

const allNum = ref(0)
const confirmNum = ref(0)
const receiveNum = ref(0)

// 请求今日待确认数量
async function reqByCustomer() {
  const res = await getByCustomer(
    {
      pageNum: 1,
      pageSize: 10
    },
    {
      btcId: userStore.btsId,
      work: true,
      keywords: '',
      wxStatus: 1,
      examineFlag: undefined,
      // startBillingTime: dayjs().format("YYYY-MM-DD"), //llz
      // endBillingTime: dayjs().format("YYYY-MM-DD"), //llz
      startBillingTime: '', //llz
      endBillingTime: '' //llz
    }
  )
  if (res.data.code === 200) {
    allNum.value = res.data.total
  }
}
reqByCustomer()

// 请求今日待审核数量
async function reqWaitForConfirm() {
  const res = await waitForConfirm({
    pageNum: 1,
    pageSize: 15,
    startBillingTime: '', //llz
    endBillingTime: '' //llz
    // startBillingTime: dayjs().format("YYYY-MM-DD"), //llz
    // endBillingTime: dayjs().format("YYYY-MM-DD"), //llz
  })
  // console.log(dayjs().subtract(7,"day").format("YYYY-MM-DD"));

  if (res.data.code === 200) {
    confirmNum.value = res.data.total
  }
}
reqWaitForConfirm()

// 请求今日待签收数量（待提货）
async function reqWaitForReceive() {
  const res = await waitForReceive({
    pageNum: 1,
    pageSize: 15,
    startBillingTime: '', //llz
    endBillingTime: '' //llz
    // startBillingTime: dayjs().format("YYYY-MM-DD"),
    // endBillingTime: dayjs().format("YYYY-MM-DD"),
  })
  if (res.data.code === 200) {
    receiveNum.value = res.data.total
  }
}
reqWaitForReceive()

/* 跳网点运单 */
const goWaybill = () => {
  Taro.navigateTo({
    url: '/pages2/waybillPage/index'
  })
}

/* 跳提货记录 */
function goPickRecord() {
  Taro.navigateTo({
    url: '/pages2/pickRecord/index'
  })
}

/* 跳发货记录 */
function goSendRecord() {
  Taro.navigateTo({
    url: '/pages2/sendRecord/index'
  })
}

/* 网点查询 */
function goNetQuery() {
  Taro.navigateTo({
    url: '/pages2/branchInquiry/index'
  })
}

/* 价格时效 */
function goPriceAdd() {
  Taro.navigateTo({
    url: '/pages2/priceTimeliness/index'
  })
}

// 用户信息
function goPersonal() {
  Taro.navigateTo({
    url: '../index/personalData'
  })
}
</script>

<style lang="scss">
.bg {
  height: 540rpx;
  padding: 24rpx;
  background-image: url('../../assets/images/homePage/shouye_img_beijing@3x.png');
  background-size: 100% 100%;
}

.person_info {
  display: flex;
  justify-content: space-between;
  height: 160rpx;
  padding-top: 90rpx;
  color: #fff;

  .person_info_son {
    display: flex;
    align-items: center;

    .headPortrait {
      width: 50rpx;
      height: 50rpx;
      margin-right: 20rpx;
    }
  }

  .site {
    font-size: 25rpx;
  }

  span {
    vertical-align: middle;
  }
}

.SearchOrder {
  margin: -120rpx 24rpx 0rpx 24rpx;
  box-shadow: 0rpx 10rpx 10rpx 5rpx rgb(192, 179, 179);
}

.footer {
  margin: 20rpx 24rpx;
  display: flex;
  justify-content: space-between;
  width: 700rpx;
  height: 184rpx;
  background-color: #fff;
  border-radius: 20rpx;
  font-size: 28rpx;
  padding: 32rpx;
  box-sizing: border-box;

  .item {
    width: 112rpx;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;

    .img {
      width: 48rpx;
      height: 48rpx;
    }
  }
}
</style>
